package com.cdks.wuxiu.api.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;

import com.cdks.wuxiu.api.model.dto.AlicloudRealnameDTO;
import com.cdks.wuxiu.common.exception.ApiException;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class AlicloudApiUtils {
    /**
     * APP_CODE
     */
    private static final String APP_CODE = "5d370bf26e2b4f959fbef18105f474dc";
    /**
     * 网关
     */
    private static final String DOMAIN = "https://zpc.market.alicloudapi.com";

    public static void realname(String idCard, String mobile, String realName) {
        Map<String, Object> bodys = new HashMap<>();
        bodys.put("idCard", idCard);
        bodys.put("mobile", mobile);
        bodys.put("realName", realName);
        String result = HttpRequest.post(DOMAIN + "/efficient/cellphone/post")
                .header("Authorization", "APPCODE " + APP_CODE)
                .form(bodys)
                .execute().body();
        log.info("实名认证 result:" + result);
        AlicloudRealnameDTO dto = JSONUtil.toBean(result, AlicloudRealnameDTO.class);
        log.info("实名认证 dto:" + dto);
        // 1 信息匹配，-1 信息不匹配，0 系统无记录
        if (dto.getErrorCode() != 0 || !dto.getResult().getVerificationResult().equals("1")) {
            throw new ApiException(60, "实名认证信息不匹配");
        }
    }
}
